
local function get_real_x(max,index,w,gap)
    local gap = gap or 50
    local x0 = (1920 - max*w - (max-1)*gap)/2
    return x0 + (index-1)*(w+gap)
end

class.select_data = extends(class.panel) {
    count = 3,
    gap = 20,
    select_y = 200,
    select_w = 300,
    select_h = 429,
    show_flag = false,
    new = function (parent,count)

        local panel = class.select_data:builder 
        {
            parent = parent,
            x = 0,
            y = 0,
            w = 1,
            h = 1,
            count = count,
        }
        return panel
    end,
    init = function (self)
        class.panel.init(self)
        --self.title = self:add_text(self.name,0,self.select_y-50,nil,30,16,5)
        self.childs = {}
        local x0 = (1920 - self.count*self.select_w - (self.count-1)*self.gap)/2
        for i = 1, self.count do 
            local child = class.button:builder {
                parent = self,
                x = get_real_x(self.count,i,self.select_w,self.gap),
                y = self.select_y,
                w = self.select_w,
                h = self.select_h,
                hover_image = [[进入]],
                index = i,
                back = {
                    type = 'panel',
                    --fdf = 'tooltip_backdrop0',
                    fdf = 'tooltip_backdrop1',
                    alpha = 0.99,
                },
                icon = {
                    type = 'panel',
                    x = (self.select_w - 128)/2,
                    y = 15,
                    w = 128,
                    h = 128,
                    --normal_image = [[textures\black32.blp]],
                    normal_image = [[天赋图标\cs.tga]],
                    level = 2,
                },
                title = {
                    y = 150,
                    h = 30,
                    type = 'text',
                    font_size = 14,
                    align = 5,
                    level = 9,
                    text = '|cffff00ff■|r|cffff33ee■|r|cffff66dd妖|r|cffff99cc精|r',
                    justH = "CENTER",
                    justV = "MIDDLE",
                    level = 5,
                },
                text = {
                    x = 10,
                    y = 190,
                    w = self.select_w - 20,
                    h = self.select_h - 200,
                    ext_w = 10,
                    type = 'text',
                    level = 5,
                    font_size = 10,
                    text = [[]],
                }
            }
            
            --启动自动换行
            child.text:set_width(child.text.w)
            self.childs[i] = child
        end 

        self:set_ignore_trackevents(false)
        self.select = self:add_panel('1',0,0,self.select_w,self.select_h)
        self.select:set_alpha(50)
        self.select:hide()

        return self 
    end,

    set_data = function (self, list)
        for i, button in ipairs(self.childs) do 
            local skill = list[i]
            button.skill = skill
            if skill then 
                local x = get_real_x(#list,i,self.select_w,self.gap)
                button:set_position(x,button.y)
                button.title:set_text(skill.title or skill.name)
                button.text:set_text(skill.tip)
                button.icon:set_normal_image(skill.art)
                button:show()
            else
                button:hide()
            end 
        end 
        self:show()
    end,
    on_button_clicked = function (self, button)
        if button.index and button.skill then 
            ac.sync(self.sync_name or self.name,button.index)
            self.select:hide()
            self:notify('on_select',button)
            self:hide()
        end 
    end,
    on_button_mouse_enter = function(self,button)
        if button.index then
            local x,y = button:get_real_position()
            self.select:set_real_position(x,y)
            self.select:show()
        end
    end,
    on_button_mouse_leave = function(self)
        self.select:hide()
    end

}

